package cn.xiaobai.captcha.handler.captchatype;

import cn.xiaobai.captcha.config.CaptchaProperties;
import com.wf.captcha.SpecCaptcha;
import lombok.extern.slf4j.Slf4j;

/**
 * 图形验证码处理器
 *
 * @Author yangdaji
 * @Date 2024/4/18
 * @PackageName cn.xiaobai.captcha.handler.captchatype
 * @ClassName GraphCaptchaHandler
 */
//@
@Slf4j
public class GraphCaptchaHandlerAbstract extends AbstractCaptchaAbstractTypeHandler {

    {
        log.info("使用默认图形验证码处理器");
    }

    public GraphCaptchaHandlerAbstract() {
    }

    public GraphCaptchaHandlerAbstract(CaptchaProperties captchaProperties) {
        super(captchaProperties);
    }

    @Override
    public String createGeneral() {
        return defaultGraph();
    }

    /**
     * 默认方式生成验证码(默认图片形式)
     *
     * @return
     */
    private String defaultGraph() {
        log.info("图片验证码生成中....");
        SpecCaptcha specCaptcha = new SpecCaptcha();
        //获取图片验证码字符串
        String graph = String.valueOf(specCaptcha.textChar());
        log.info("图片验证码生成完成,即将写入流中!");
        //将验证码放入流中
        specCaptcha.out(this.getOutputStream());
        return graph;
    }
}
